package com.qcby.mycommunity_003.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qcby.mycommunity_003.entity.Camera;
import com.qcby.mycommunity_003.entity.Community;
import com.qcby.mycommunity_003.mapper.CameraMapper;
import com.qcby.mycommunity_003.mapper.CommunityMapper;
import com.qcby.mycommunity_003.service.CameraService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.mycommunity_003.vo.CameraListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-03-28
 */
@Service
public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> implements CameraService {

    @Autowired
    private CameraMapper cameraMapper;
    @Autowired
    private CommunityMapper communityMapper;

    /**
     * 展示摄像头列表
     * @param commuityId
     * @return
     */
    @Override
    public ArrayList<CameraListVo> CameraList(Integer commuityId) {
        ArrayList<CameraListVo> list=new ArrayList<>();
        QueryWrapper<Camera> queryWrapper=new QueryWrapper<>();
        //查询社区id为指定id的list
        queryWrapper.eq("community_id",commuityId);
        //查询指定id的社区信息
        Community community = communityMapper.selectById(commuityId);
        //查询指定id的摄像头信息
        List<Camera> cameras = cameraMapper.selectList(queryWrapper);
        for (Camera camera : cameras) {
        CameraListVo cameraListVo=new CameraListVo();
        cameraListVo.setCameraInfoId(camera.getCameraId());
        cameraListVo.setCameraName(camera.getCameraName());
        cameraListVo.setCommunityId(commuityId);
        cameraListVo.setMacID(camera.getMacId());
        cameraListVo.setDirection(camera.getDirection());
        cameraListVo.setState(camera.getState());
        cameraListVo.setSeq(camera.getSeq());
        cameraListVo.setCreater(camera.getCreater());
        cameraListVo.setRemark(camera.getRemark());
        cameraListVo.setCreateTime(camera.getCreateTime());
        cameraListVo.setCommunityName(community.getCommunityName());
        list.add(cameraListVo);
        }
        return list;
    }
}
